<template>
  <el-table :data="tableData" fit border size="mini">
    <el-table-column prop="name" label="楼盘名称"></el-table-column>
    <!-- <el-table-column prop="cityAreaName" label="区域商圈"></el-table-column> -->
    <el-table-column prop="aliasShow" label="楼盘划区" width="250"></el-table-column>
    <el-table-column prop="type" label="类型"></el-table-column>
    <el-table-column prop="deliveryTime" label="交付时间" sortable></el-table-column>
    <el-table-column prop="totalUnit" label="栋数" sortable></el-table-column>
    <el-table-column label="户数">
      <template slot-scope="scope">
        <span>{{scope.row.totalHouses}}</span>
        <!-- <el-button type="text" v-if="scope.row.totalHouses!=0" size="small" @click="roomNumber(scope.row)">[查看]</el-button> -->
      </template>
    </el-table-column>
    <el-table-column label="操作" width="180">
      <template slot-scope="scope">
        <el-button type="text" size="small" @click="pedestalList(scope.row)">栋座设置</el-button>
        <el-button type="text" size="small" @click="addPB('edit',scope.row)">编辑楼盘</el-button>
        <el-button type="text" size="small" @click="del(scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
import { request } from "../../assets/request.js";
export default {
  data() {
    return {
      tableData: [
        {
          name: "左邻右舍公寓",
          tradingArea: "西湖区/保椒路",
          address: "上海市普陀区金沙江路 1518 弄",
          type: "别墅",
          years: "2018-12-01",
          buildings: 5,
          household: 100
        }
      ],
      obj:{
        size:20,
        page:1
      }
    };
  },
  created() {
    let that=this
    this.selectList(that.obj);
    this.$root.$on("refresh",data=>{
      if(data!='no'){
        let obj= this.obj
        obj.page=data.page
      }
      console.log(that.obj)
      this.selectList(that.obj);
    })
    this.$root.$on("onSubmit",data=>{
      console.log(data)
      that.obj=data
      this.selectList(data);
    })
  },
  methods: {
    del(row) {
      let that=this
      // console.log(row.id)
      request.delAlert({
          name:'删除该楼盘',
          that,
          fn(obj){
              let url='houses/'+row.id+'?greenToken='+request.greenToken
              request.ajaxDel({
                url,
                that,
                fn(res){
                  that.$message(obj)
                  that.selectList(that.obj);
                }
              })
          }
      })
    },
    roomNumber() {
      this.$router.push({
        path: "roomNumber"
      });
    },
    pedestalList(row) {
      this.$root.$emit("pedestalList", row);
    },
    addPB(type,row) {
      this.$root.$emit("addPB", type,row);
    },
    selectList(obj) {
      let url = "houses";
      let that=this   //解决this指向问题
      request.ajaxGet({
        url,
        that,
        params:obj,
        fn(res){
          console.log(res)
          that.$root.$emit("propertBank",res.total)
          var data=res.list
          that.tableData=data
        }
      })
    }
  }
};
</script>

